package com.csdj.springcloudt309.order.aop;

import com.csdj.springcloudt309.order.service.UserServiceRpc;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class FeginDemo implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //方法上面的注解
        RequestMapping annotation = method.getAnnotation(RequestMapping.class);
        RequestMethod[] methods = annotation.method();
        String[] urls = annotation.value();
        method.getGenericExceptionTypes();

        Class<?> declaringClass = method.getDeclaringClass();
        Class<?>[] interfaces = declaringClass.getInterfaces();
        //接口上面的注解
        FeignClient annotation1 = interfaces[0].getAnnotation(FeignClient.class);
        String serviceId = annotation1.name();
        return null;
    }

    public static UserServiceRpc getProxy(){
        UserServiceRpc userServiceRpc = (UserServiceRpc)Proxy.newProxyInstance(FeginDemo.class.getClassLoader(),new Class[]{UserServiceRpc.class},new FeginDemo());
        return userServiceRpc;
    }
}
